package com.mail.server.controller;


import com.mail.model.db.OmsOrder;
import com.mail.model.db.OmsOrderSetting;
import com.mail.server.common.R;
import com.mail.server.service.OrderSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单设置表 前端控制器
 * </p>
 *
 * @author WJZ
 * @since 2022-06-20
 */
@RestController
@RequestMapping("/orderSetting")
public class OmsOrderSettingController {

    @Autowired
    private OrderSettingService orderSettingService;

    /**
     * 修改指定订单设置
     *
     * @param id:订单设置表中的主键id(按理说是订单id)
     * @param orderSetting:订单设置数据
     * @return
     */
    @PostMapping("/update/{id}")
    public R update(@PathVariable Integer id, @RequestBody OmsOrderSetting orderSetting) {
        Integer count = orderSettingService.update(id, orderSetting);
        if (count == 0) {
            return R.error("修改失败");
        }
        return R.success("修改成功!");
    }

    /**
     * 获取指定订单设置
     *
     * @param id：订单设置表中的主键id(按理说是订单id)
     * @return
     */
    @GetMapping("/{id}")
    public R findById(@PathVariable Integer id) {
        OmsOrderSetting orderSetting = orderSettingService.findById(id);
        if (orderSetting == null) {
            return R.error("查询有误");
        }
        return R.success(orderSetting);
    }
}
